package com.cci.kangdao.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.ThirdApiService;
import com.cci.kangdao.utilTool.ParameterTool;
/**
 * @Description: 第三方接口
 * @Company: CTY
 * @author 米艳春
 * @date 2018-01-19
 * @version 1.0
 */
@Controller
public class ThirdApi {
	private Logger log = Logger.getLogger(this.getClass().getName());

	@Autowired
	private ThirdApiService thirdApiService;

	/**
	 * App数码防伪查询接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/digitalQuery.aspx")
	public ModelAndView digitalQuery(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return thirdApiService.digitalQuery(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	/**
	 * App上传物流跟踪接口
	 * @param map
	 * @return
	 */
	@RequestMapping("/uploadLogistics.aspx")
	public ModelAndView uploadLogistics(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return thirdApiService.uploadLogistics(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
}
